package net.ojbk.study.twobox.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.ojbk.study.twobox.beans.po.Job;
import net.ojbk.study.twobox.beans.po.Jobcompany;
import net.ojbk.study.twobox.beans.po.Student;
import net.ojbk.study.twobox.beans.vo.JoinJob;
import net.ojbk.study.twobox.beans.vo.SelectOption;
import net.ojbk.study.twobox.dao.ClassMapper;
import net.ojbk.study.twobox.dao.JobMapper;
import net.ojbk.study.twobox.dao.JobcompanyMapper;
import net.ojbk.study.twobox.dao.StudentMapper;
import net.sf.jsqlparser.statement.select.Join;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: twobox
 * Date: 2019/4/18
 * Time: 12:58
 * Description: No Description
 */
@Service
public class O_JoinJobService {

    @Autowired
    ClassMapper classMapper;

    @Autowired
    JobcompanyMapper jobcompanyMapper;

    @Autowired
    StudentMapper studentMapper;

    @Autowired
    JobMapper jobMapper;

    public void toJob(JoinJob joinJob) throws Exception {
        Student student = studentMapper.selectByPrimaryKey(joinJob.getId());
        student.setStustate("刚入职");
        studentMapper.updateByPrimaryKeySelective(student);
        // 创建新的Job信息
        Job job = new Job();
        job.setStucode(student.getStucode());
        job.setGender(student.getStusex());
        job.setClassid(student.getClassid());
        job.setStuname(student.getStuname());
        // 获取公司
        Jobcompany jobcompany = jobcompanyMapper.selectByPrimaryKey(joinJob.getJobcomid());

        job.setJobcomid(jobcompany.getId());
        job.setLocation(jobcompany.getAddress());
        job.setJobstate("已就业");
        job.setJobtime(new Date());

        jobMapper.insert(job);
    }

    public List<SelectOption> getAll_Class() throws Exception {
        return classMapper.getAllClass();
    }

    public List<SelectOption> getAll_Jobcompany() throws Exception {
        return jobcompanyMapper.getAll_Jobcompany();
    }

    public PageInfo<JoinJob> getAll_JoinJob_ByClassId(int page, int classId) throws Exception {
        PageHelper.startPage(page, 15);
        List<JoinJob> list = studentMapper.getAll_JoinJob_ByClassId(classId);
        PageInfo<JoinJob> joinJobPageInfo = new PageInfo<>(list);
        return joinJobPageInfo;
    }

}
